//
//  Session.m
//  ZZmetro
//
//  Created by 一介布衣 on 2020/6/5.
//  Copyright © 2020 一介布衣. All rights reserved.
//

#import "Session.h"
#import "UserDefaultsKey.h"

@implementation Session
/**
 判断用户是否已经登录
 */
+(BOOL)isLogin{
    return Session.accountName && Session.passWord && Session.cookie ? YES : NO;
}

/**
 当前登录账户
 */
+(void)setAccountName:(NSString *)accountName{
    if(!accountName){
        [CommonLocalStorage.share removeObjectForKey:keyForAccountName];
        return;
    }
    [CommonLocalStorage.share setObject:accountName forKey:keyForAccountName];
}

+(NSString*)accountName{
    return [CommonLocalStorage.share stringForKey:keyForAccountName];
}

/**
 登录密码
 */
+ (void)setPassWord:(NSString *)passWord
{
    if (!passWord) {
        [CommonLocalStorage.share removeObjectForKey:keyForAccountPassWord];
        return;
    }
    [CommonLocalStorage.share setObject:passWord forKey:keyForAccountPassWord];
}

+ (NSString *)passWord
{
    return [CommonLocalStorage.share stringForKey:keyForAccountPassWord];
}

/**
 登录token
 */
+ (void)setToken:(NSString *)token
{
    if (!token) {
        [CommonLocalStorage.share removeObjectForKey:keyForAccountToken];
        return;
    }
    [CommonLocalStorage.share setObject:token forKey:keyForAccountToken];
}

+ (NSString *)token
{
    return [CommonLocalStorage.share stringForKey:keyForAccountToken];
}

/**
 登录token
 */
+ (void)setCookie:(NSString *)cookie
{
    if (!cookie) {
        [CommonLocalStorage.share removeObjectForKey:keyForAccountCookie];
        return;
    }
    [CommonLocalStorage.share setObject:cookie forKey:keyForAccountCookie];
}

+ (NSString *)cookie
{
    return [CommonLocalStorage.share stringForKey:keyForAccountCookie];
}

/**
 清除用户信息
 */
+(void)clear{
    Session.accountName = NULL;
    Session.passWord = NULL;
    Session.token = NULL;
    Session.cookie = NULL;
}

@end
